/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.yonsei.iwb.srf.classifier;

import edu.yonsei.iwb.sdt.refinement.generator.*;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.RDF;
import java.util.List;
import java.util.Vector;
import edu.yonsei.iwb.sdt.algorithm.DCSSearcher;
import edu.yonsei.iwb.sdt.datastructure.tree.BranchingType;
import edu.yonsei.iwb.sdt.datastructure.DecomposeCandidate;
import edu.yonsei.iwb.sdt.datastructure.DecomposeCandidateSet;
import edu.yonsei.iwb.sdt.datastructure.TargetInstance;
import edu.yonsei.iwb.sdt.ontology.PropertyArc;
import edu.yonsei.iwb.sdt.refinement.ConjunctionRefinement;
import edu.yonsei.iwb.sdt.refinement.DLConstructors;
import edu.yonsei.iwb.sdt.refinement.ExpandingHistory;
import edu.yonsei.iwb.sdt.refinement.ExpandingHistorySet;
import edu.yonsei.iwb.sdt.refinement.Refinement;
import edu.yonsei.iwb.sdt.refinement.RefinementType;
import edu.yonsei.iwb.sdt.util.SDTLog;
import edu.yonsei.iwb.ts.TSSearch;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author JDK
 */
public class ConjunctionRefinementClassifier {
    public Vector<String> satisfiedSet(Vector<String> insset, String cenclass, String conclass) throws IOException {
        Vector<String> hisset = getSatisfiedInstanceSet(cenclass, conclass);
        Vector<String> resultset = new Vector();
        for (int i = 0; i < insset.size(); i++) {
            String ins = insset.get(i);
            if(hisset.contains(ins)){
                resultset.add(ins);
            }
        }
        return resultset;
    }

    public Vector<String> satisfiedSet(Vector<String> insset, String centerclass, String conclass, Vector<PropertyArc> pset, Vector<String> qset) throws IOException {

        
        Vector<String> resultset = new Vector();
        QuantificationRefinementClassifier qrc = new QuantificationRefinementClassifier();
        Vector<String> hisinsset = getSatisfiedInstanceSet(centerclass, conclass);
        for (int i = pset.size() - 1; i > -1; i--) {
            PropertyArc hisp = pset.get(i);
            Hashtable<String,ArrayList<String>> pastrset = qrc.getPastResAndValueTable(hisp);
            String quantifier = qset.get(i);
            if (quantifier.equals(DLConstructors.EXISTENTIAL)) {
                hisinsset = qrc.getExistentialResources(hisinsset, hisp, pastrset);
            } else {
                hisinsset = qrc.getUniversalResources(hisinsset, hisp, pastrset);
            }
        }
                        
        for (int i = 0; i < hisinsset.size(); i++) {
            String ins = hisinsset.get(i);
            if(insset.contains(ins)){
                resultset.add(ins);
            }
        }

        return resultset;           
    }

    private Vector<String> getSatisfiedInstanceSet(String cenclass, String conclass) throws IOException {
        Vector<String> css = new Vector<String>();

        ArrayList<String> cen = TSSearch.listSubjectResource(RDF.type.getURI(), cenclass);
        ArrayList<String> con = TSSearch.listSubjectResource(RDF.type.getURI(), conclass);

        for (int i = 0; i < cen.size(); i++) {
            if (con.contains(cen.get(i))) {
                if (!css.contains(cen.get(i))) {
                    css.add(cen.get(i));
                }
            }
        }

        return css;
    }
}
